package com.a.lib_bean.api;

import android.util.Log;
import com.hjq.http.annotation.HttpIgnore;
import com.hjq.http.config.IRequestApi;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class ParamsApi implements IRequestApi {

    @NotNull
    @Override
    public String getApi() {
        Log.i("TAG", "getApi: " + api);
        return api.toString();
    }

    public ParamsApi(String url, String s) {
        this.api.append(url).append(s);
    }

    public static ParamsApi newObjectParamsApi(String url, Map<String, Object> params) {
        StringBuilder api = new StringBuilder()
                .append("?");
        for (String key : params.keySet()) {
            api.append(key).append("=").append(params.get(key)).append("&");
        }
        return new ParamsApi(url, api.toString());
    }

    @HttpIgnore
    private final StringBuilder api = new StringBuilder();

    public<T> ParamsApi(String url, Map<String, T> params) {
        this.api.append(url).append("?");
        for (String key : params.keySet()) {
            this.api.append(key).append("=").append(params.get(key)).append("&");
        }
    }


}
